import { ProLayoutProps, SettingDrawer } from '@ant-design/pro-layout';
import { getAllLocales, setLocale, useIntl, useModel } from 'umi';
import React, { useEffect, useState } from 'react';
import { Button, message } from 'antd';
import { LogoutOutlined } from '@ant-design/icons';
import { logout } from '@/pages/user/login/service';

const rightContentRender: ProLayoutProps['rightContentRender'] = (props) => {
  // const { initialState, loading, error, refresh, setInitialState } =
  //   useModel('@@initialState');
  // const intl = useIntl();
  // const [settings, setSettings] = useState({});
  //
  // // 设置中文
  // useEffect(() => setLocale('zh-CN', false), []);
  //
  // useEffect(() => {
  //   console.log(initialState, loading, error, refresh, setInitialState);
  //   console.log(getAllLocales());
  //   console.log(intl.formatMessage({ id: 'menu.home' }));
  //   console.log(
  //     intl.formatMessage({
  //       id: 'menu.home1',
  //       description: '???',
  //       defaultMessage: '默认值',
  //     }),
  //   );
  // }, []);
  //
  // useEffect(() => {
  //   console.log('---------SettingDrawer----------->', settings);
  //   setInitialState({ ...initialState, settings } as any);
  // }, [settings]);

  return (
    <>
      <Button
        type="link"
        icon={<LogoutOutlined />}
        onClick={() => {
          logout().then((response) => {
            if (response?.code == '200') {
              message.success('登出成功');
              sessionStorage.removeItem('currentUser');
              window.location.href = '/';
            } else {
              message.error(response?.message || '登出失败');
            }
          });
        }}
      >
        登出
      </Button>
      {/*<div hidden>*/}
      {/*  <SettingDrawer*/}
      {/*    enableDarkTheme*/}
      {/*    settings={settings}*/}
      {/*    onSettingChange={setSettings}*/}
      {/*  />*/}
      {/*</div>*/}
    </>
  );
};

export default rightContentRender;
